package com.wangyadong.hobby.test;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

public class People {

    public volatile int age;
    private String name;

    public People() {
    }

    public People(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    //朝九晚五时间
    public static void main(String[] args) {

    }

    private static final LocalTime BASESTARTTIME = LocalTime.of(9, 0);
    private static final LocalTime BASEENDTIME = LocalTime.of(16, 59, 59);


    public static long compute(LocalDateTime startTime, LocalDateTime endTime) {
        if (startTime == null || endTime == null) {
            return 0l;
        }
        if (startTime.compareTo(endTime) > 0) {
            return 0l;
        }
        LocalDate startLocalDate = startTime.toLocalDate();
        LocalDate endLocalDate = endTime.toLocalDate();
        LocalTime startLocalTime = startTime.toLocalTime();
        LocalTime endLocalTime = endTime.toLocalTime();
        LocalDateTime localDateTime = validateStartTime(startLocalDate, startLocalTime);
        LocalDateTime localDateTime1 = validatEndTime(endLocalDate, endLocalTime);
        Map<LocalDateTime, LocalDateTime> localDateTimeMap = new HashMap<>();
        //是一天
        if (startLocalDate.compareTo(endLocalDate) == 0) {
            Duration between = Duration.between(localDateTime, localDateTime1);
            return between.toMillis();
        }
        localDateTimeMap.put(localDateTime, LocalDateTime.of(startLocalDate, BASEENDTIME));
        localDateTimeMap.put(LocalDateTime.of(endLocalDate, BASESTARTTIME), localDateTime1);
        LocalDate startDate = startLocalDate.plusDays(1);
        while (startDate.compareTo(endLocalDate) < 0) {
            localDateTimeMap.put(LocalDateTime.of(startDate, BASESTARTTIME), LocalDateTime.of(startDate, BASEENDTIME));
            startDate = startLocalDate.plusDays(1);
        }

        localDateTimeMap.forEach((k, v) -> {
            Duration between = Duration.between(k, v);
        });


        //隔天的情况


        return 0l;
    }

    private static LocalDateTime validateStartTime(LocalDate localDate, LocalTime localTime) {
        LocalDateTime localDateTime = null;
        boolean startFlag = localTime.compareTo(BASESTARTTIME) <= 0;
        if (startFlag) {
            return LocalDateTime.of(localDate, BASESTARTTIME);
        }
        startFlag = localTime.compareTo(BASEENDTIME) > 0;
        if (startFlag) {
            return localDateTime;
        } else {
            localDateTime = LocalDateTime.of(localDate, localTime);
        }
        return localDateTime;
    }

    //结束时间
    private static LocalDateTime validatEndTime(LocalDate localDate, LocalTime localTime) {
        LocalDateTime localDateTime = null;
        boolean startFlag = localTime.compareTo(BASEENDTIME) > 0;
        if (startFlag) {
            return LocalDateTime.of(localDate, BASEENDTIME);
        }
        startFlag = localTime.compareTo(BASESTARTTIME) <= 0;
        if (startFlag) {
            return localDateTime;
        } else {
            localDateTime = LocalDateTime.of(localDate, localTime);
        }
        return localDateTime;
    }


}
